﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
namespace EDMS
{
    public partial class MainMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断用户是否已经登录
            try
            {
                if (!CMSUser.Current.IsLogin)
                {
                    Response.Redirect("~/Login.aspx");
                }
            }
            catch (Exception)
            {
                Response.Redirect("~/Login.aspx");
            }
            NavDataBind();
        }

        //显示类型
        private void NavDataBind()
        {
            this.ASPxNavType.Groups.Clear();
            this.ASPxNavType.Font.Size = FontUnit.Parse("10pt");
            if (Cache["NavDatalist"] == null)        //获取或设置指定键外的缓存项
            {
                using (DAL.DataClassesDataContext lqDB = new DataClassesDataContext())
                {
                    Cache["NavDatalist"] = lqDB.Functions.ToList();
                }
            }

            //先获取数据
            List<DAL.Functions> AllList = Cache["NavDatalist"] as List<DAL.Functions>;          //所有内容
            List<DAL.Functions> groupList = AllList.Where(o => o.ParentID == "0").ToList();     //一级节点
            foreach (DAL.Functions group in groupList)
            {
                DevExpress.Web.ASPxNavBar.NavBarGroup NvGroup = this.ASPxNavType.Groups.Add(group.Description, group.FunctionID);   //显示内容
                List<DAL.Functions> itemlist = AllList.Where(o => o.ParentID == group.FunctionID).ToList();   //列出对应的二级内容
                foreach (DAL.Functions item in itemlist)
                {
                    //判断是否拥有操作权限
                    if (CMSUser.Current.CheckActionAllow(item.FunctionID))
                    {
                        NvGroup.Items.Add(item.Description, item.FunctionID, string.Empty, item.Url);
                    }
                }
            }
        }
    }
}